/*******************************************************************************************
Copyright (C) 2016 Mestrelab Research S.L. All rights reserved.

This file is part of the MNova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*******************************************************************************************/

/*globals Str, Utl*/
/*jslint plusplus: true, bitwise: true, indent: 4*/

function brukerDate(aStr) {
	"use strict";

	var time = parseInt(aStr, 10), date;
	if (isNaN(time)) {
		return aStr;
	}

	date = new Date(time * 1000);

	return Str.date2ISOString(date);
}

function brukerDate2(aStr, aParmDateStr, aParmTimeStr) {
	"use strict";

	if (aParmDateStr !== undefined && aParmTimeStr !== undefined && aParmDateStr.length === 8 && (aParmTimeStr.length === 5 || aParmTimeStr.length === 4)) {
		var year = parseInt(aParmDateStr.substring(0, 4), 10),
			month = parseInt(aParmDateStr.substring(4, 6), 10) - 1,
			day = parseInt(aParmDateStr.substring(6, 8), 10),
			hourLen = 2,
			hour,
			min,
			result;

		if (aParmTimeStr.length === 4) {
			hourLen = 1;
		}
		hour = parseInt(aParmTimeStr.substring(0, hourLen), 10);
		min = parseInt(aParmTimeStr.substring(hourLen + 1, hourLen + 3), 10);

		result = new Date(year, month, day, hour, min);

		return Str.date2ISOString(result);
	}

	return brukerDate(aStr);
}

function varianDate(aDateTime, aDateTime1, aDateTime2) {
	"use strict";

	if (aDateTime.length === 15 && aDateTime.charAt(8) === 'T') {
		var year = parseInt(aDateTime.substring(0, 4), 10),
			month = parseInt(aDateTime.substring(4, 6), 10) - 1,
			day = parseInt(aDateTime.substring(6, 8), 10),
			hour = parseInt(aDateTime.substring(9, 11), 10),
			min = parseInt(aDateTime.substring(11, 13), 10),
			sec = parseInt(aDateTime.substring(13, 15), 10),
			result;

		result = new Date(year, month, day, hour, min, sec);

		return Str.date2ISOString(result);
	}

	return Str.firstNotEmptyString(aDateTime, aDateTime1, aDateTime2);
}

function jeolDate(aDate) {
	"use strict";

	var date = parseInt(aDate, 10),
		year = 1990 + ((date & 0xfe000000) >> 25),
		month = ((date & 0x01e00000) >> 21) - 1,
		day = (date & 0x001f0000) >> 16,
		seconds = date & 0x0000ffff,
		result;

	result = new Date(year, month, day);
	result.setSeconds(Math.round(seconds * 1.318379));
	return Str.date2ISOString(result);
}

function jeolParamDate(aDate) {
	"use strict";

	return Str.date2ISOString(new Date(aDate * 1000 + 631180800 * 1000));
}

function galacticDate(aNewFormat, aOldYear, aOldDateRest, aFileCreateDate) {
	"use strict";

	function prepend0(aNumber) {
		if (aNumber === undefined) {
			return "";
		}
		if (aNumber < 10) {
			return "0" + aNumber.toString();
		}
		return aNumber.toString();
	}

	var day, month, year, hour, min;
	if (aNewFormat) {
		day = (aNewFormat << 16) >>> 27;
		month = (aNewFormat << 12) >>> 28;
		year = aNewFormat >>> 20;
		hour = (aNewFormat << 21) >>> 27;
		min = (aNewFormat << 26) >>> 26;
	} else if (aOldYear && aOldDateRest) {
		year = Number(aOldYear);
		if (year < 1900) {
			year += 1900;
		}
		month = (aOldDateRest << 24) >>> 24;
		day = (aOldDateRest << 16) >>> 24;
		hour = (aOldDateRest << 8) >>> 24;
		min = aOldDateRest >>> 24;
	}
	if (aNewFormat || (aOldYear && aOldDateRest)) {
		return year + "-" + prepend0(month) + "-" + prepend0(day) + "T" + prepend0(hour) + ":" + prepend0(min) + ":00";
	}
	return aFileCreateDate;
}

function brukerPulseWidth(aPw, aPulseSeq) {
	"use strict";

	var pw =  aPw * 1.0e-6;
	if (aPulseSeq.indexOf("bp", 0) !== -1) {
		pw = pw * 2;
	}
	return pw;
}

function brukerExpName(aFilePath, aExpName, aExpNo, aProcNo) {
	"use strict";

	var newPath = aFilePath.replace(/\\/g, "/"),
		matchRes,
		pathArray;

	if (aExpName && aExpNo && aProcNo && aExpName.length) {
		matchRes = newPath.match(/\/(fid|1r|ser|2rr)$/i);

		if (matchRes && matchRes.length === 2) {
			if (["fid", "ser"].indexOf(matchRes[1].toLowerCase()) !== -1) {
				return aExpName + "." + aExpNo + "." + matchRes[1];
			}
			return aExpName + "." + aExpNo + "." + aProcNo + "." + matchRes[1];
		}
		return aExpName + "." + aExpNo + "." + aProcNo;
	}

	// WinNMR
	matchRes = newPath.match(/^([\/]*)\/(\d{6}\.(?:fid|1r|ser|rr))$/i);
	if (matchRes && matchRes.length === 3) {
		return matchRes[1] + "." + matchRes[2];
	}

	// UXNMR FID's
	matchRes = newPath.match(/^([\w\W]*\/)*([\w\W]*)\/(\d+)\/(fid|ser)$/i);
	if (matchRes && matchRes.length >= 4) {
		return matchRes[matchRes.length - 3] + "." + matchRes[matchRes.length - 2] + "." + matchRes[matchRes.length - 1];
	}

	// UXNMR spectra
	matchRes = newPath.match(/^([\w\W]*\/)*([\w\W]*)\/(\d+)\/pdata\/(\d+)\/(1r|2rr)$/i);
	if (matchRes && matchRes.length >= 5) {
		return matchRes[matchRes.length - 4] + "." + matchRes[matchRes.length - 3] + "." + matchRes[matchRes.length - 2] + "." + matchRes[matchRes.length - 1];
	}

	pathArray = newPath.split("/");
	if (pathArray.length < 3) {
		return aFilePath;
	}
	return pathArray[pathArray.length - 3] + "/" + pathArray[pathArray.length - 2];
}

function brukerExpNo(aFilePath, aExpNo) {
	"use strict";

	var newPath = aFilePath.replace(/\\/g, "/"),
		matchRes;

	if (aExpNo) {
		return aExpNo;
	}

	// UXNMR FID's
	matchRes = newPath.match(/^([\w\W]*\/)*([\w\W]*)\/(\d+)\/(fid|ser)$/i);
	if (matchRes && matchRes.length >= 4) {
		return matchRes[matchRes.length - 2];
	}

	// UXNMR spectra
	matchRes = newPath.match(/^([\w\W]*\/)*([\w\W]*)\/(\d+)\/pdata\/(\d+)\/(1r|2rr)$/i);
	if (matchRes && matchRes.length >= 5) {
		return matchRes[matchRes.length - 3];
	}

	return "";

}

function brukerProcNo(aFilePath, aProcNo) {
	"use strict";

	var newPath = aFilePath.replace(/\\/g, "/"),
		matchRes;

	if (aProcNo) {
		return aProcNo;
	}

	// UXNMR spectra
	matchRes = newPath.match(/^([\w\W]*\/)*([\w\W]*)\/(\d+)\/pdata\/(\d+)\/(1r|2rr)$/i);
	if (matchRes && matchRes.length >= 5) {
		return matchRes[matchRes.length - 2];
	}

	return "";

}

function varianExpName(aFilePath) {
	"use strict";

	var newPath = aFilePath.replace(/\\/g, "/"),
		pathArray = newPath.split("/"),
		result;

	if (pathArray.length < 2) {
		return aFilePath;
	}
	result = pathArray[pathArray.length - 2];
	if (result.length > 4 && result.substring(result.length - 4, result.length).toLowerCase() === ".fid") {
		result = result.substring(0, result.length - 4);
	}
	return result;
}

function jcampDate(aJCAMP, aBruker, aVarian, aJeol, aLongJCamp, aJCampTime) {
	"use strict";

	if (aLongJCamp) {
		return aLongJCamp.replace(/\//g, "-").replace(" ", "T");
	}
	if (aJCAMP) {
		if (/\d\d\/\d\d\/\d\d/.test(aJCAMP)) {
			if (aJCAMP[0] === '0') {
				aJCAMP = '20' + aJCAMP;
			} else {
				aJCAMP = '19' + aJCAMP;
			}
			aJCAMP = aJCAMP.replace(/\//g, "-");
		}
		if (aJCampTime) {
			return aJCAMP + 'T' + aJCampTime;
		}
		return aJCAMP;
	}
	if (aVarian) {
		return varianDate(Str.unBracket(aVarian, "<", ">"));
	}
	if (aBruker) {
		return brukerDate(aBruker);
	}
	if (aJeol) {
		return aJeol;
	}
	return '';
}

function jcampAcquiredSize(aBruker, aVarian, aJeol) {
	"use strict";

	if (aBruker.length) {
		return Utl.div(aBruker, 2.0);
	}
	if (aVarian.length) {
		return Utl.div(aVarian, 2.0);
	}
	if (aJeol.length) {
		return aJeol;
	}
	return "";
}

function brukerAQ(aAQ, aSW, aTD) {
	"use strict";

	if (!isNaN(parseFloat(aAQ))) {
		return aAQ;
	}
	return 0.5 * aTD / aSW;
}

function jcampAQ(aAQ, aSW, aTD) {
	"use strict";

	if (!isNaN(parseFloat(aAQ))) {
		return aAQ;
	}
	if (!isNaN(parseFloat(aTD)) && !isNaN(parseFloat(aSW))) {
		return 0.5 * aTD / aSW;
	}
	return "";
}

function jeolInstrument(aInstrument, aCode) {
	"use strict";

	if (aInstrument.length) {
		return aInstrument;
	}

	switch (parseInt(aCode, 10)) {
	case 0:
		return "NONE";
	case 1:
		return "GSX";
	case 2:
		return "ALPHA";
	case 3:
		return "ECLIPSE";
	case 4:
		return "MASS_SPEC";
	case 5:
		return "COMPILER";
	case 6:
		return "OTHER_NMR";
	case 7:
		return "UNKNOWN";
	case 8:
		return "GEMINI";
	case 9:
		return "UNITY";
	case 10:
		return "ASPECT";
	case 11:
		return "UX";
	case 12:
		return "FELIX";
	case 13:
		return "LAMBDA";
	case 14:
		return "GE_1280";
	case 15:
		return "GE_OMEGA";
	case 16:
		return "CHEMAGNETICS";
	case 17:
		return "CDFF";
	case 18:
		return "GALACTIC";
	case 19:
		return "TRIAD";
	case 20:
		return "GENERIC_NMR";
	case 21:
		return "GAMMA";
	case 22:
		return "JCAMP_DX";
	case 23:
		return "AMX";
	case 24:
		return "DMX";
	case 25:
		return "ECA";
	case 26:
		return "ALICE";
	case 27:
		return "NMR_PIPE";
	default:
		return "";
	}
}

function varianExperimentType(aSeqfil, aMbond, aMult) {
	"use strict";

	aSeqfil = aSeqfil.toLowerCase();
	if (aMbond === undefined) {
		aMbond = "";
	}
	aMbond = aMbond.toLowerCase();
	if (aMult === undefined) {
		aMult = "";
	}

	var result;

	if (varianExperimentType.userFunction !== undefined) {
		result = varianExperimentType.userFunction(aSeqfil, aMbond);
		if (result.length) {
			return result;
		}
	}

	if (aSeqfil === "gcosy" || aSeqfil === "relayh") {
		return "2D-COSY";
	}
	if (aSeqfil === "gdqcosy") {
		return "2D-DQF-COSY";
	}
	if (aSeqfil === "hom2dj") {
		return "2D-JRES";
	}
	if (aSeqfil.indexOf("noesy1d") === 0) {
		return "1D-NOESY";
	}
	if (aSeqfil.indexOf("roesy1d") === 0) {
		return "1D-ROESY";
	}
	if (aSeqfil.indexOf("tocsy1d") === 0) {
		return "1D-TOCSY";
	}
	if (aSeqfil === "noesy" || aSeqfil === "gnoesy" || aSeqfil === "noesy_da" || aSeqfil === "tnnoesy" || aSeqfil === "gtnnoesy") {
		return "2D-NOESY";
	}
	if (aSeqfil.indexOf("roesy") === 0 || aSeqfil.indexOf("tnroesy") === 0 || aSeqfil.indexOf("tnoroesy") === 0 || aSeqfil.indexOf("groesy") === 0 || aSeqfil.indexOf("wgroesy") === 0 || aSeqfil.indexOf("gtnroesy") === 0 || aSeqfil.indexOf("wroesy") === 0 || aSeqfil.indexOf("troesy") === 0) {
		return "2D-ROESY";
	}
	if ((aSeqfil.indexOf("hmqc") === 0 || aSeqfil.indexOf("ghmqc") === 0) && (aMbond === "n" || aMbond === "")) {
		return "2D-HMQC";
	}
	if ((aSeqfil.indexOf("hmqc") === 0 || aSeqfil.indexOf("ghmqc") === 0) && aMbond === "y") {
		return "2D-HMQC-MB";
	}
	if (aSeqfil.indexOf("tocsy") === 0 || aSeqfil.indexOf("tntocsy") === 0  || aSeqfil.indexOf("tnotocsy") === 0 || aSeqfil.indexOf("wgtocsy") === 0) {
		return "2D-TOCSY";
	}
	if (aSeqfil.indexOf("ghsqctoxy") === 0 || aSeqfil.indexOf("hsqctoxy") === 0 || aSeqfil.indexOf("ghsqctocsy") === 0 || aSeqfil.indexOf("hsqctocsy") === 0) {
		if (aMult === "2") {
			return "2D-HSQC-TOCSY-EDITED";
		}
		return "2D-HSQC-TOCSY";
	}
	if (aSeqfil.indexOf("hsqc") === 0 || aSeqfil.indexOf("ghsqc") === 0 || aSeqfil.indexOf("gchsqc") === 0 || aSeqfil.indexOf("gnhsqc") === 0 || aSeqfil.indexOf("wghsqc") === 0) {
		if (aMult === "2") {
			return "2D-HSQC-EDITED";
		}
		return "2D-HSQC";
	}
	if (aSeqfil.indexOf("hmbc") === 0 || aSeqfil.indexOf("ghmbc") === 0) {
		return "2D-HMBC";
	}
	if (aSeqfil.indexOf("h2bc") === 0 || aSeqfil.indexOf("gh2bc") === 0) {
		return "2D-H2BC";
	}
	if (aSeqfil === "hetcor") {
		return "2D-HETCOR";
	}
	if (aSeqfil.indexOf("inad") === 0) {
		return "2D-INADEQUATE";
	}
	if (aSeqfil === "dept") {
		return "1D-DEPT-135";
	}
	if (aSeqfil === "inept") {
		return "1D-INEPT";
	}
	if (aSeqfil === "apt") {
		return "1D-APT";
	}
	return "";
}

varianExperimentType.userFunction = undefined;

function brukerExperimentType(aParameters) {
	"use strict";

	var result, cnst2, pulprog = "";
	
	if (typeof aParameters === "object") {
		if (aParameters.pulprog !== undefined) {
			pulprog = aParameters.pulprog.toLowerCase();
		}
		if (aParameters.cnst2 !== undefined) {
			cnst2 = aParameters.cnst2;
		}		
	}
	else {
		pulprog = aParameters.toLowerCase();
	}

	if (brukerExperimentType.userFunction !== undefined) {
		result = brukerExperimentType.userFunction(pulprog);
		if (result.length) {
			return result;
		}
	}

	if (pulprog === "noesy1d" || pulprog === "noesypr1d") {
		return "1D-NOESY";
	}
	if (pulprog.indexOf("noesy") === 0) {
		return "2D-NOESY";
	}
	if (pulprog.indexOf("roesy") === 0 || pulprog.indexOf("easyroesy") === 0) {
		return "2D-ROESY";
	}
	if (pulprog.indexOf("hxco") === 0) {
		return "2D-HETCOR";
	}
	if (pulprog.indexOf("cosy") === 0 && pulprog.indexOf("df") !== -1) {
		return "2D-DQF-COSY";
	}
	if (pulprog.indexOf("cosy") === 0) {
		return "2D-COSY";
	}
	if (pulprog.indexOf("mlev") === 0 || (pulprog.indexOf("tocsy") !== -1 && pulprog.indexOf("hsqc") === -1)) {
		return "2D-TOCSY";
	}
	if (pulprog.indexOf("hmbc") === 0 || (pulprog.indexOf("inv4") === 0 && pulprog.indexOf("lr") !== -1)) {
		return "2D-HMBC";
	}
	if ((pulprog.indexOf("hsqc") === 0 || pulprog.indexOf("invi") === 0) && pulprog.indexOf("ed") !== -1) {
		return "2D-HSQC-EDITED";
	}
	if ((pulprog.indexOf("hsqc") === 0 || pulprog.indexOf("invi") === 0) && pulprog.indexOf("ml") !== -1) {
		return "2D-HSQC-TOCSY";
	}
	if (pulprog.indexOf("inv4") === 0 || pulprog.indexOf("invi") === 0 || pulprog.indexOf("hsqc") === 0 || pulprog.indexOf("asap_hsqc") === 0) {
		return "2D-HSQC";
	}
	if (pulprog.indexOf("hmqc") === 0) {
		if (pulprog.indexOf("hmqcgpqf") === 0 && cnst2 !== undefined && cnst2 < 100) {
			return "2D-HMBC";
		}
		return "2D-HMQC";
	}
	if (pulprog.indexOf("dept") === 0 && pulprog.indexOf("135") !== -1) {
		return "1D-DEPT-135";
	}
	if (pulprog.indexOf("dept") === 0 && pulprog.indexOf("45") !== -1) {
		return "1D-DEPT-45";
	}
	if (pulprog.indexOf("dept") === 0 && pulprog.indexOf("90") !== -1) {
		return "1D-DEPT-90";
	}
	if (pulprog.indexOf("jmod") === 0) {
		return "1D-JMOD";
	}
	if (pulprog.indexOf("inad") === 0) {
		return "2D-INADEQUATE";
	}
	return "";
}

brukerExperimentType.userFunction = undefined;

function prospaExperimentType(aPulprog) {
	"use strict";

	aPulprog = aPulprog.toLowerCase();

	var result;

	if (prospaExperimentType.userFunction) {
		result = prospaExperimentType.userFunction(aPulprog);
		if (result && result.length) {
			return result;
		}
	}

	if (aPulprog.indexOf("cosy") === 0) {
		return "2D-COSY";
	}
	if (aPulprog.indexOf("hmqc") === 0) {
		return "2D-HMQC";
	}
	if (aPulprog.indexOf("hsqc") === 0) {
		return "2D-HSQC";
	}
	if (aPulprog.indexOf("hmbc") === 0) {
		return "2D-HMBC";
	}
	return "";
}

prospaExperimentType.userFunction = undefined;

function qonetecExperimentType(aPulprog) {
	"use strict";

	aPulprog = aPulprog.toLowerCase();

	var result;

	if (qonetecExperimentType.userFunction) {
		result = qonetecExperimentType.userFunction(aPulprog);
		if (result && result.length) {
			return result;
		}
	}

	if (aPulprog.indexOf("cosy") === 0) {
		return "2D-COSY";
	}
	if (aPulprog.indexOf("hsqc") === 0) {
		return "2D-HSQC";
	}
	if (aPulprog.indexOf("heter2dj") === 0) {
		return "2D-JRES";
	}
	if (aPulprog.indexOf("tocsy") === 0) {
		return "2D-TOCSY";
	}
	return "";
}

qonetecExperimentType.userFunction = undefined;

function jeolExperimentType(aPulprog) {
	"use strict";

	aPulprog = aPulprog.toLowerCase();

	var result;

	if (jeolExperimentType.userFunction) {
		result = jeolExperimentType.userFunction(aPulprog);
		if (result && result.length) {
			return result;
		}
	}

	if (aPulprog.indexOf("cosy") === 0) {
		return "2D-COSY";
	}
	if (aPulprog.indexOf("hmqc") === 0) {
		return "2D-HMQC";
	}
	if (aPulprog.indexOf("hsqc") === 0) {
		return "2D-HSQC";
	}
	if (aPulprog.indexOf("hmbc") === 0) {
		return "2D-HMBC";
	}
	return "";
}

jeolExperimentType.userFunction = undefined;

function brukerAspectRG(aReadRG) {
	"use strict";

	return Math.floor((aReadRG - 24555) / 2.1346);
}

function varianPresatFreq(tof, satfrq, satmode, sw, sfrq, rfp, rfl) {
	"use strict";

	var ref;

	tof = parseFloat(tof);
	satfrq = parseFloat(satfrq);
	sw = parseFloat(sw);
	sfrq = parseFloat(sfrq);
	rfp = parseFloat(rfp);
	rfl = parseFloat(rfl);

	if (isNaN(rfp)) {
		rfp = 0;
	}
	if (isNaN(rfl)) {
		rfl = 0;
	}
	ref = rfp - rfl;

	if (isNaN(tof)) {
		tof = 0;
	}
	if (isNaN(satfrq)) {
		tof = satfrq = 0;
	}

	if (isNaN(sw) || isNaN(sfrq)) {
		return "";
	}

	satmode = satmode.toLowerCase();
	if (satmode.indexOf("y") >= 0) {
		return ((0.5 * Number(sw) + ref  + Number(satfrq) - Number(tof)) / Number(sfrq));
	}
	return "";
}

function brukerPresatOffsetFromList(list) {
	"use strict";
	var arrayOfLines, offset;

	arrayOfLines = list.split(/[\r\n]+/g);
	offset = 0.0;
	if (arrayOfLines[0].indexOf("O") >= -1) {
		if (arrayOfLines.length >= 3) {
			offset = Number(arrayOfLines[1]) - Number(arrayOfLines[2]);
		}
	} else {
		if (arrayOfLines.length >= 2) {
			offset = Number(arrayOfLines[0]) - Number(arrayOfLines[1]);
		}
	}
	return offset;
}


function brukerPresatFreq($PULPROG, $SPOFFS6, $SFO1, $O1, $SW, procs_$OFFSET, fq0list) {
	"use strict";

	$PULPROG = $PULPROG.toLowerCase();
	if ($PULPROG.indexOf('zgpr') === -1 && $PULPROG.indexOf('zgps') === -1 && $PULPROG.indexOf('wet') === -1 &&	$PULPROG.indexOf('noesygppr') === -1 && $PULPROG.indexOf('watergate') === -1  && $PULPROG.indexOf('zggpw5') === -1 && $PULPROG.indexOf('cpmges') === -1 && $PULPROG.indexOf('zggpwg') === -1 && $PULPROG.indexOf('zgesgp') === -1 && $PULPROG.indexOf('noesypr1d') === -1 && $PULPROG.indexOf('zgfqpr') === -1) {
		return "";
	}
	if ($PULPROG.indexOf('zgfqpr') > -1 && fq0list) {
		$SPOFFS6 = brukerPresatOffsetFromList(fq0list);
	} else {
		$SPOFFS6 = parseFloat($SPOFFS6);
	}
	$SFO1 = parseFloat($SFO1);
	$O1 = parseFloat($O1);
	$SW = parseFloat($SW);
	procs_$OFFSET = parseFloat(procs_$OFFSET);

	if (!isNaN($SW) && !isNaN(procs_$OFFSET) && !isNaN($SFO1)) {
		$O1 = (Number(procs_$OFFSET) - 0.5 * Number($SW)) * Number($SFO1);
	}

	if (isNaN($SPOFFS6) || isNaN($SFO1) || isNaN($O1) || Number($SFO1) === 0) {
		return "";
	}
	return (Number($O1) + Number($SPOFFS6)) / Number($SFO1);
}

function jcampExperimentType(aPulprog, aPulseSequence) {
	"use strict";

	if (aPulprog && aPulprog.length > 0) {
		return brukerExperimentType(Str.unBracket(aPulprog, "<", ">"));
	}

	var result = "";
	if (aPulseSequence) {
		if (aPulseSequence === "COSY") {
			result = "2D-COSY";
		} else if (aPulseSequence === "HSQC") {
			result = "2D-HSQC";
		} else if (aPulseSequence === "JRES") {
			result = "2D-JRES";
		}
	}
	return result;
}

function oxfordInstrumentsTitle(aFileName) {
	'use strict';

	var arr = aFileName.split(/[\/\\]/);
	if (arr) {
		return arr[arr.length - 1];
	}
	return aFileName;
}

function oxfordInstrumentsToValidString(aStr) {
	'use strict';

	if (aStr === '????') {
		return '';
	}
	return aStr;
}
